package com.lineage.config;

import com.lineage.DatabaseFactoryLogin;
import com.lineage.server.utils.SQLUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public final class ConfigServer {
  private static final Log _log = LogFactory.getLog(ConfigServer.class);
  
  public static boolean DBClearAll;
  
  public static void loadDB() {
    Connection cn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    int size = 0;
    int i = 0;
    try {
      cn = DatabaseFactoryLogin.get().getConnection();
      ps = cn.prepareStatement("SELECT * FROM `config_server`");
      rs = ps.executeQuery();
      while (rs.next()) {
        String id = rs.getString("id");
        String set = rs.getString("设置");
        int set_int = 0;
        boolean set_boolean = false;
        if (set.equalsIgnoreCase("false") || set.equalsIgnoreCase("true")) {
          set_boolean = rs.getBoolean("设置");
        } else {
          try {
            set_int = rs.getInt("设置");
          } catch (Exception exception) {}
        } 
        if (id.equalsIgnoreCase("DBClearAll")) {
          DBClearAll = set_boolean;
          i++;
        } 
      } 
    } catch (SQLException e) {
      _log.error(e.getLocalizedMessage(), e);
    } finally {
      SQLUtil.close(rs);
      SQLUtil.close(ps);
      SQLUtil.close(cn);
    } 
    _log.info("Config->Server设置: 0笔 / 处理: " + i + "笔");
  }
}
